from random import randint
import json
import logging
from django.test import TestCase
from rest_framework.test import APIClient, force_authenticate, APIRequestFactory
from users.models import UserInfo,WeiboUser

log = logging

# Create your tests here.

weibo_id = ""
while weibo_id.__len__() < 10:
    weibo_id += str(randint(0, 9))

class WeiboTest(TestCase):

    def setUp(self):
        #wself.factory = APIRequestFactory()
        self.weibouserlogin_url = "/operation-manage/weibouser-login/"
        user = UserInfo.objects.create(username="test")
        self.weibo_id_test = ""
        while self.weibo_id_test.__len__() < 10:
            self.weibo_id_test += str(randint(0, 9))
        WeiboUser.objects.create(weibo_id=self.weibo_id_test, user=user)

    def test_weibouser_can_create(self):
        data = {
            'weibo_id': weibo_id,
            'username': 'this_is_test'
        }
        response = self.client.post(self.weibouserlogin_url, data=data)
        self.assertEqual("user create success", json.loads(response.content)['result'])

    def test_weibouser_can_login(self):
        data = {
            'weibo_id': self.weibo_id_test,
            'username': 'test'
        }
        response = self.client.post(self.weibouserlogin_url, data=data)
        self.assertEqual("user exist login success", json.loads(response.content)['result'])
